package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dto.QuizzeDTO;
import beans.QuestionaireBeanRemote;
import beans.TestBean;

/**
 * Servlet implementation class TestServlet
 */
public class TestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
    @EJB
    private QuestionaireBeanRemote sf2;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}
	
	
	
	 
	    protected void processRequest( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	    {
	        try
	        {
	        	final List<QuizzeDTO> allQuizzes = sf2.getAllQuizzes();
	        	TestBean testBean = new TestBean();
	        	testBean.setAllQuestions(allQuizzes.get(0).getName());
	        	request.getSession().setAttribute("quizzes", testBean);
	        	RequestDispatcher dispatcher =
	        			 getServletContext().getRequestDispatcher("/search.jsp");
	        			 dispatcher.forward(request, response);
	        }
	        finally
	        {
	        }
	    }
	
	   



}
